//
//  HPYVisitorViewController.swift
//  SwiftVVBo
//
//  Created by hepeiyong on 16/8/9.
//  Copyright © 2016年 hpyhn. All rights reserved.
//

import UIKit

class HPYVisitorViewController: UIViewController {

    // 判断用户是否登录
    var isLogin: Bool = HPYUserAccountViewModel.sharedTools.isLogin

    // 访客视图view
    var visitorView: HPYVisitorView?

    override func loadView() {
        if isLogin {
            view = tableView
        }else {
            setupVisitorView()
        }
    }
    // MARK: - 设置访客视图
    func setupVisitorView(){
        setupNav()
        visitorView = HPYVisitorView()
        // 02 闭包的实例化
        visitorView?.closure = {
            // 04
            self.loginAction()
        }
        view = visitorView
    }
    // 设置导航
    func setupNav(){
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "loginAction")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginAction")
    }

    // MARK: - 监听方法
    func loginAction(){
        let oauthVc = HPYOAuthViewController()
        presentViewController(UINavigationController(rootViewController: oauthVc), animated: true, completion: nil)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    // MARK: - 懒加载控件
    lazy var tableView: UITableView = UITableView()
    
    
}
